
layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate;
    var url = "/general/erp5/public/tripapi/negotiation/TravelNotSalerChatSave";
    var approveurl = "/general/erp5/public/tripapi/negotiation/ApproveTo";

    //日期
    laydate.render({
        elem: '#test1'
    });
    laydate.render({
        elem: '#test2'
    });

    //自定义验证规则
    form.verify({
        title: function(value){
            if(value.length == 0){
                return '请输入项目/合同名称';
            }
        },
        content: function(value){
            layedit.sync(editIndex);
        }
    });

    //提交
    form.on('submit(demo1)', function(data){
        $.ajax({
            type: "POST",
            url: url,
            data: data.field,
            traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
            dataType:"json",
            success: function(returnData){
                if(returnData.status == 200){
                    $.get("/general/erp5/public/common.php?opt=send_msg&params="+returnData.data.params, function(result){
                        layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,id: 'layerDemo'
                            ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
                            ,btn: '确定'
                            ,btnAlign: 'c'
                            ,shade: 0
                            ,yes: function(){
                                layer.closeAll();
                            }
                        });
                    });
                }else{
                    layer.open({
                        type: 1
                        ,offset: 'auto'
                        ,id: 'layerDemo'
                        ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
                        ,btn: '确定'
                        ,btnAlign: 'c'
                        ,shade: 0
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }
            }
        })
        // layer.alert(JSON.stringify(data.field), {
        //   title: '最终的提交信息'
        // })
        return false;
    });

    //提交
    form.on('submit(demo3)', function(data){
        $.ajax({
            type: "POST",
            url: approveurl,
            data: data.field,
            traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
            dataType:"json",
            success: function(returnData){
                if(returnData.status == 200){
                    layer.open({
                        type: 1
                        ,offset: 'auto'
                        ,id: 'layerDemo'
                        ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
                        ,btn: '确定'
                        ,btnAlign: 'c'
                        ,shade: 0
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }else{
                    layer.open({
                        type: 1
                        ,offset: 'auto'
                        ,id: 'layerDemo'
                        ,content: '<div style="padding: 20px 100px;">'+ returnData.msg +'</div>'
                        ,btn: '确定'
                        ,btnAlign: 'c'
                        ,shade: 0
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }
            }
        })
        // layer.alert(JSON.stringify(data.field), {
        //   title: '最终的提交信息'
        // })
        return false;
    });

});